<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">项目所属单位</label>
                        <div class="layui-input-block">
                            <div id="chanid" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>
<script>

    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;


        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        setSouTableExport('应收风险预警表(按单位)');
        var mytable = table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_zi_dan_tong),where: {}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text,totalRow: true
            ,parseData: function (res) {

                xmselect_dan('chanid', res.data.chanid, res.data.is_chanid, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type: "checkbox", fixed: 'left'}
                ,{type:'numbers',title:'序号',totalRowText: '合计',fixed:'left'}
                ,{field: 'name', title: '所属单位'}
                ,{field:'shimoney',title:'施工合同金额(含变更) A',totalRow: true,align:'right',event: 'contract_shi',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.shimoney)+'</span>';
                    }}
                ,{field: 'lei_chan', title: '累计审定产值 B',totalRow: true,align:'right',event: 'engin_chan',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.lei_chan)+'</span>';
                    }}
                ,{field: 'lei_piaokai', title: '累计开票 C',totalRow: true,align:'right',event: 'piao_kai',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.lei_piaokai)+'</span>';
                    }}
                ,{field: 'lei_huikuan', title: '累计回款 D',totalRow: true,align:'right',event: 'income_engin',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.lei_huikuan)+'</span>';
                    }}
                ,{field: 'lei_huihe', title: '回款占比按合同 D/A',totalRow: true,align:'right',templet: function(d){
                        return parseFormatNum(d.lei_huihe)+'%';
                    }}
                ,{field: 'lei_huishen', title: '回款占比按审定 D/B',totalRow: true,align:'right',templet: function(d){
                        return parseFormatNum(d.lei_huishen)+'%';
                    }}
                ,{field: 'lei_huikai', title: '回款占比按开票 D/C',totalRow: true,align:'right',templet: function(d){
                        return parseFormatNum(d.lei_huikai)+'%';
                    }}
                ,{field: 'lei_shenwei', title: '已审定未开票 B-C',totalRow: true,align:'right',templet: function(d){
                        if(d.lei_shenwei > 0){
                            return '<span class="colorhong">'+parseFormatNum(d.lei_shenwei)+'</span>';
                        }else{
                            return parseFormatNum(d.lei_shenwei);
                        }
                    }}
                ,{field: 'lei_weihui', title: '已审定未回款 B-D',totalRow: true,align:'right',templet: function(d){
                        if(d.lei_weihui > 0){
                            return '<span class="colorhong">'+parseFormatNum(d.lei_weihui)+'</span>';
                        }else{
                            return parseFormatNum(d.lei_weihui);
                        }
                    }}
                ,{field: 'lei_kaiwei', title: '已开票未回款 C-D',totalRow: true,align:'right',templet: function(d){
                        if(d.lei_kaiwei > 0){
                            return '<span class="lei_kaiwei">'+parseFormatNum(d.lei_kaiwei)+'</span>';
                        }else{
                            return parseFormatNum(d.lei_kaiwei);
                        }
                    }}
            ]]
            , done: function (res) {
                soulTable.render(this);
            }
        });

        table.on('tool(datalist)',function (obj) {
            var data = obj.data;
            if(obj.event === 'contract_shi'){
                openPage('../contract_shi/tong.php?chanid='+data.id+'&status=1', '80%', '80%');
            }
            if(obj.event === 'engin_chan'){
                openPage('../engin_chan/tong.php?chanid='+data.id+'&status=1', '80%', '80%');
            }
            if(obj.event === 'piao_kai'){
                openPage('../piao_kai/tong.php?chanid='+data.id+'&status=1', '80%', '80%');
            }
            if(obj.event === 'income_engin'){
                openPage('../income_engin/tong.php?chanid='+data.id+'&status=1&budname='+encodeURI('工程款'), '80%', '80%');
            }
        });


        listTableSearch(form, table);
    });




</script>
</body>
</html>
